function [OUT_Symbols] = HF_Scrambling (IN_Frame,Rate)

%*------------------------------------------ HF_Scrambling ------------------------------------------%
%
% [OUT_Symbols] = HF_Scrambling (IN_Frame,Rate)
%
% The fuction that scrambles the input frame dependent on the (Rate), and
% hence the length of input frame length must match with the corressponding
% rate as follows:
%
%
%           Rate            |           Input Frame Length
%
%           3200           |                    512
%           4800           |                    768
%           6400           |                    1024
%           8000           |                    1280
%           9600           |                    1536
%
%
%*----------------------------------------------------------------------------------------------------%

global LFSR_out

LUT_Frame = [512,768,1024,1280,1536]; %frame lengths corressponding to the rates.
Data_Rates = [3200 4800 6400 8000 9600 12800];
Rate_Index = find(Data_Rates==Rate);

% the following condition to accept the input rate and interleaver size
if (LUT_Frame(Rate_Index) ~= length(IN_Frame))
    disp('Error : the input frame length doesnot match with the corressponding rate')
    Rate_Index = 0;
    LUT_Frame(Rate_Index);
end


%---------------------------------- SCRAMBLING & LFSR OPERATIONS ------------------------------%

% SCRAMBLING OPERATION
%----------------------------
if (Rate == 3200 || Rate == 4800)   % case of QPSK and 8PSK scrambling
    Data_Symbols_Q_8 = Symbol_Mapping (IN_Frame,Rate,1);
    % transform the output of the LFSR to integer format
    OUT_Symbols = mod(Data_Symbols_Q_8+LFSR_out,8);  %#ok, modulo 8 addition

else  % case of all except Q/8PSK
    Data_Symbols_Others = Symbol_Mapping (IN_Frame,Rate,0);
    Data_Symbols_Xored = bitxor(Data_Symbols_Others,LFSR_out);%#ok
    % xor with the equivalent symbol bit sequence
    % get the corresponging integer form
    OUT_Symbols = bi2de(Data_Symbols_Xored);
end

%-----------------------------------------------------------------------------------------------------%

